package com.lscl.rabbitmq;

import org.springframework.amqp.core.AcknowledgeMode;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.QueueBuilder;
import org.springframework.amqp.rabbit.config.ListenerContainerFactoryBean;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.support.ListenerContainerAware;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class);
    }

    @Bean
    public RedisTemplate redisTemplate(RedisTemplate redisTemplate){

        // value可见
        redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());

        // key可见
        redisTemplate.setKeySerializer(new StringRedisSerializer());

        return redisTemplate;
    }

    // 定义测试队列
    @Bean
    public Queue testQueue(){
        return QueueBuilder.durable("test_queue").build();
    }

    // 测试顺序消费队列
    @Bean
    public Queue orderQueue(){
        // 独占队列
        return QueueBuilder.durable("order_queue").exclusive().build();
    }

}